//请放jQuery后
//同步表单ajax提交未加密
function ajaxRequestPost(map) {
    map.key=JSON.parse(localStorage.getItem('key'));
	showDialog();
    var resultData=null;
    $.ajax({
        type: "POST",
        url:url_prefix+map.url,
        data:map,
        dataType: 'JSON',
		timeout: 10000,
        async :false,
        success: function(data) {
			dismissDialog();
            var str1 = decryptByDESModeEBC(data["result"]); //解密
            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
            var datas = JSON.stringify(str2); //转JSON字符串
            var aa = datas.replace(/\\n/g, " "); //去掉换行
            var objs = eval('(' + aa + ')');
            var bb = eval('(' + objs + ')');
            if(bb.head.status == 1) {
                resultData=bb;
            } else {
                resultData=bb;
                mui.alert(bb.head.info);
            }
        },
        error: function(data) {
			dismissDialog();
            mui.alert("Connection error");
        }
    });
    return resultData;
}

function ajaxRequestPostS(map) {
    map.key=JSON.parse(localStorage.getItem('key'));
	showDialog();
    var resultData=null;
    $.ajax({
        type: "POST",
        url:url_prefix+map.url,
        data:map,
        dataType: 'JSON',
		timeout: 10000,
        success: function(data) {
			dismissDialog();
            var str1 = decryptByDESModeEBC(data["result"]); //解密
            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
            var datas = JSON.stringify(str2); //转JSON字符串
            var aa = datas.replace(/\\n/g, " "); //去掉换行
            var objs = eval('(' + aa + ')');
            var bb = eval('(' + objs + ')');
            if(bb.head.status == 1) {
               localStorage.setItem('getsynestrusdata', JSON.stringify(bb.data.overbitList));
            } else {
                localStorage.setItem('getsynestrusdata', JSON.stringify(bb.data.overbitList));
                mui.alert(bb.head.info);
            }
        },
        error: function(data) {
			dismissDialog();
            mui.alert("Connection error");
        }
    });
	
}

/** 提交请求 */
function ajaxRequestPostSubmit(map) {
    map.key=JSON.parse(localStorage.getItem('key'));
	showDialog();
    var resultData=null;
    $.ajax({
        type: "POST",
        url:url_prefix+map.url,
        data:map,
        dataType: 'JSON',
		timeout: 10000,
        async :false,
        success: function(data) {
			dismissDialog();
            var str1 = decryptByDESModeEBC(data["result"]); //解密
            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
            var datas = JSON.stringify(str2); //转JSON字符串
            var aa = datas.replace(/\\n/g, " "); //去掉换行
            var objs = eval('(' + aa + ')');
            var bb = eval('(' + objs + ')');
            console.log(bb);
            if(bb.head.status == 1) {
                resultData=bb;
                mui.alert(bb.head.info);
            } else {
                resultData=bb;
                mui.alert(bb.head.info);
            }
        },
        error: function(data) {
			dismissDialog();
            mui.alert("Connection error");
        }
    });
    return resultData;
}

//异步ajaxDES加密封装
function ajaxRequestPostEDS(callBackFunction,map) {
    map.key=JSON.parse(localStorage.getItem('key'));
    map.phoneType = "android";
    map.language = "zh";
    var jsonStr = JSON.stringify(map);
	showDialog();
    $.ajax({
        type: "POST",
        url:url_prefix+map.url,
		timeout: 10000,
        data: {
            'request': encryptByDES(jsonStr)
        },
        dataType: 'JSON',
        success: function(data) {
			dismissDialog();
            var str1 = decryptByDESModeEBC(data["result"]); //解密
            var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
            var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
            var datas = JSON.stringify(str2); //转JSON字符串
            var aa = datas.replace(/\\n/g, " "); //去掉换行
            var objs = eval('(' + aa + ')');
            var bb = eval('(' + objs + ')');
            if(bb.head.status == 1) {
                callBackFunction(bb);
            } else {
                mui.alert(bb.head.info);
            }
        },
        error: function(data) {
			localStorage.setItem('equipmentID', JSON.stringify(1));
			dismissDialog();
            mui.alert("Connection error");
        }
    });
}

//表单序列化json对象
$.fn.serializeObject = function() {
    var o = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (o[this.name]) {
            if (!o[this.name].push) {
                o[this.name] = [ o[this.name] ];
            }
            o[this.name].push(this.value || '');
        } else {
            o[this.name] = this.value || '';
        }
    });
    return o;
};
function showDialog() {
	var opts = {
		lines: 13, // 花瓣数目
		length: 10, // 花瓣长度
		width: 5, // 花瓣宽度
		radius: 15, // 花瓣距中心半径
		scale: 1,
		corners: 1, // 花瓣圆滑度 (0-1)
		color: '#000', // 花瓣颜色
		opacity: 0.25,
		rotate: 0, // 花瓣旋转角度
		direction: 1, // 花瓣旋转方向 1: 顺时针, -1: 逆时针
		speed: 1, // 花瓣旋转速度
		trail: 60, // 花瓣旋转时的拖影(百分比)
		zIndex: 2e9, // spinner的z轴 (默认是2000000000)
		className: 'spinner', // spinner css 样式名称
		top: '350%', // spinner 相对父容器Top定位 单位 px
		shadow: false, // 花瓣是否显示阴影
		hwaccel: false, //spinner 是否启用硬件加速及高速旋转 
		position: 'absolute'
	};
	spinner = new Spinner(opts);
	$(".spin").show();
	var target = $(".spin")[0];
	spinner.spin(target);
}

function dismissDialog() {
	if(spinner != undefined) {
		spinner.spin();
	}
}
function dtPicker(str){
		           var dtPicker = new mui.DtPicker({ type: 'date' });
		           /*参数：'datetime'-完整日期视图(年月日时分)
		                   'date'--年视图(年月日)
		                   'time' --时间视图(时分)
		                   'month'--月视图(年月)
		                   'hour'--时视图(年月日时)
		           */      
		           dtPicker.show(function (selectItems) {
		              var y = selectItems.y.text;  //获取选择的年
		              var m = selectItems.m.text;  //获取选择的月
		              var d = selectItems.d.text;  //获取选择的日
		              var date = y + "-" + m + "-" + d ; 
		              $("#"+str).val(date); 
		           })
	}
